package a_File1;

import org.junit.Test;

import java.io.File;

/*
    获取路径的方式
 */
public class PathDemo02 {
    @Test //方式一: 默认位置生成
    public void pathTest01(){
        File file = new File("a.txt");
        String path = file.getAbsolutePath();
        //D:\Idea-workspace\api_2207\api_day09\a.txt
        System.out.println(path);
    }

    @Test //方式二: 获取 在和本类的同包下b.txt
    public void pathTest02(){
        //获取相对路径的方法
        String path = PathDemo02.class.getResource("b.txt").getPath();
        /*D:/Idea-workspace/api_2207/
            out/production/api_day09/a_file/b.txt */
        System.out.println(path);
    }

    @Test //方式三: 获取 src下的c.txt
    public void pathTest03(){
        String path = PathDemo02.class.getClassLoader()
                .getResource("c.txt").getPath();
        // D:/Idea-workspace/api_2207/out/production/api_day09/c.txt
        System.out.println(path);
    }

}
